#!/bin/bash

ROOT_PATH=$(cd $(dirname $0) && pwd);

apt purge -y softether-vpnserver
apt autoremove -y

apt -y install softether-vpnserver

ADMIN=$(cat $ROOT_PATH/cfg/sadmin.secret)
PASS=$(cat $ROOT_PATH/cfg/user.secret)

sh -c "echo '
ServerPasswordSet '$ADMIN'
HubDelete DEFAULT

HubCreate Z /PASSWORD:'$ADMIN'


Hub Z
SecureNatEnable
DhcpSet /START:10.126.251.100 /END:10.126.251.199 /MASK:255.255.255.0 /EXPIRE:7200 /GW:10.126.251.2 /DNS:10.126.251.2 /LOG:yes /DNS2:none /DOMAIN:none
SecureNatHostSet /MAC:none /IP:10.126.251.2 /MASK:255.255.255.0

UserCreate prx /GROUP:none /REALNAME:none /NOTE:none
UserPasswordSet prx /PASSWORD:'$PASS'

UserCreate user /GROUP:none /REALNAME:none /NOTE:none
UserPasswordSet user /PASSWORD:'$PASS'

UserCreate prz-client /GROUP:none /REALNAME:none /NOTE:none
UserPasswordSet prz-client /PASSWORD:'$PASS'


Reboot

' > /tmp/softether.config"


sudo vpncmd localhost /SERVER /in:/tmp/softether.config

service softether-vpnserver restart

#rm /tmp/softether.config


### iptables ###

iptables -A INPUT -m tcp -p tcp --dport 443 -j ACCEPT

netfilter-persistent save
